﻿using System.Configuration;

namespace DataGeneration.Domain.Helpers
{
    /// <summary>
    /// Defines the type ApplicationSettings
    /// </summary>
    public static class ApplicationSettings
    {
        public static void ConfigSystem()
        {
            ParameterizedAppSettings.DatabaseConnectionString = DatabaseConnectionString;
            ParameterizedAppSettings.DatabaseType = DatabaseType;
            ParameterizedAppSettings.DataLoadScriptsFolder = DataLoadScriptsFolder;
            ParameterizedAppSettings.EntitiesFilename = EntitiesFilename;
            ParameterizedAppSettings.SequenceDataFile = SequenceDataFile;
            ParameterizedAppSettings.SilentMode = false;
        }
        public static SupportedDatabase DatabaseType
        {
            get
            {
               return EnumHelper.Convert<SupportedDatabase>(ConfigurationManager.AppSettings["DatabaseType"],true);
            }
        }
        /// <summary>
        /// Gets the sequence data file.
        /// </summary>
        /// <value>The sequence data file.</value>
        public static string SequenceDataFile
        {
            get
            {
                return ConfigurationManager.AppSettings["SequenceDataFile"];
            }
        }

        /// <summary>
        /// Gets the input file.
        /// </summary>
        /// <value>The input file.</value>
        public static string InputFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InputFile"];
            }
        }

        /// <summary>
        /// Gets the entities filename.
        /// </summary>
        /// <value>The entities filename.</value>
        public static string EntitiesFilename
        {
            get
            {
                return ConfigurationManager.AppSettings["EntitiesFilename"];
            }
        }

        /// <summary>
        /// Gets the data load scripts folder.
        /// </summary>
        /// <value>The data load scripts folder.</value>
        public static string DataLoadScriptsFolder
        {
            get
            {
                return ConfigurationManager.AppSettings["DataLoadScriptsFolder"];
            }
        }

        /// <summary>
        /// Gets the database connection string.
        /// </summary>
        /// <value>The database connection string.</value>
        public static string DatabaseConnectionString
        {
            get
            {
                return ConfigurationManager.ConnectionStrings["DefaultDB"].ConnectionString;
            }
        }

        /// <summary>
        /// Generates the entity SQL filename.
        /// </summary>
        /// <param name="patternName">Name of the pattern.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <returns></returns>
        public static string GenerateEntitySqlFilename(string patternName, string entityName)
        {
            return string.Format(@"{0}{1}\SQL\{2}.sql", DataLoadScriptsFolder, patternName, entityName);
        }
        /// <summary>
        /// Generates the entity key filename.
        /// </summary>
        /// <param name="patternName">Name of the pattern.</param>
        /// <param name="entityTableName">Name of the entity table.</param>
        /// <returns></returns>
        public static string GenerateEntityKeyFilename(string patternName, string entityTableName)
        {
            return string.Format(@"{0}{1}\Keys\{2}.key", DataLoadScriptsFolder, patternName, entityTableName);
        }
        /// <summary>
        /// Generates the batch filename.
        /// </summary>
        /// <param name="patternName">Name of the pattern.</param>
        /// <param name="batchNo">The batch no.</param>
        /// <returns></returns>
        public static string GenerateBatchFilename(string patternName,int batchNo)
        {
            return string.Format(@"{0}{1}\SQL\{2}.sql", DataLoadScriptsFolder, patternName, batchNo);
        }

        /// <summary>
        /// Generates the patter filename.
        /// </summary>
        /// <param name="patternName">Name of the pattern.</param>
        /// <returns></returns>
        public static string GeneratePatterFilename(string patternName)
        {
            return string.Format(@"{0}{1}.xml", DataLoadScriptsFolder, patternName);
        }

        /// <summary>
        /// Generates the entity CSV filename.
        /// </summary>
        /// <param name="patternName">Name of the pattern.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <returns></returns>
        public static string GenerateEntityCsvFilename(string patternName, string entityName)
        {
            return string.Format(@"{0}{1}\CSV\{2}.csv", DataLoadScriptsFolder, patternName, entityName);
        }
        
    }
}


